package com.example.demo.handler;

import com.example.demo.common.entity.MsgInfo;
import com.example.demo.exception.BusinessException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class BusinessExceptionHandler {
    
    @ExceptionHandler(BusinessException.class)
    public MsgInfo error(BusinessException e) {
        return MsgInfo.error().code(e.getCode()).msg(e.getMessage()).setData(e.getData());
    }
    
}
